/**
 * 
 */
package com.geekteam.geometrychess.handler.event;

import com.geekteam.geometrychess.extension.ChessExtension;
import com.geekteam.geometrychess.utils.Commands;
import com.geekteam.geometrychess.utils.Utils;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;

/**
 * @author MtRol
 *
 */
public class LeaveRoomEventHandler extends BaseServerEventHandler{

	@Override
	public void handleServerEvent(ISFSEvent event) throws SFSException {
		Room room = (Room) event.getParameter(SFSEventParam.ROOM);
		User user = (User) event.getParameter(SFSEventParam.USER);
		ChessExtension extension = (ChessExtension) this.getParentExtension();
		
		if(room==null || user==null)
			return;
		
		if(room.isGame()){
			//TODO: toannv handler if player in room game
		}else{
			ISFSObject sfsObject = Utils.toSFSObject(user);
			send(Commands.USER_LEAVE_ROOM, sfsObject, room.getUserList());
		}
	}

}
